package com.yh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yh.common.BaseResult;
import com.yh.entity.User;
import org.springframework.web.bind.annotation.*;
import com.yh.service.IUserService;
import lombok.AllArgsConstructor;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2021-05-10
 */
@AllArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {
    private final IUserService sysUserService;

    @GetMapping("/getPage")
    public BaseResult getPageUser(Integer pageNum,Integer pageSize){
        Page<User> page = sysUserService.getPageUser(pageNum, pageSize);
        return BaseResult.success(page);
    }

    @PostMapping("/save")
    public BaseResult save(User user){
        user = sysUserService.saveUser(user);
        return BaseResult.success(user);
    }

    @PutMapping("/update")
    public BaseResult update(User user){
        user = sysUserService.updateUser(user);
        return BaseResult.success(user);
    }

    @GetMapping("/getInfo")
    public BaseResult getInfo(String id){
        User user = sysUserService.getInfo(id);
        return BaseResult.success(user);
    }
}

